<template>
  <div>
    <el-switch
      :active-text="$t('sys.menu.on')"
      :active-value="1"
      :inactive-text="$t('sys.menu.off')"
      :inactive-value="0"
      :model-value="row.status"
      inline-prompt
      @update:model-value="changeStatus(row)"
    />
  </div>
</template>

<script setup lang="ts">
import { $t } from '@vben/locales';

const props = defineProps({
  row: {
    type: Object,
    required: true,
  },
  requestApi: {
    type: Function,
    required: true,
  },
});

async function changeStatus(row: any): Promise<void> {
  await props.requestApi({
    id: row.id,
    status: Number(!row.status),
    ...row,
  });
  row.status = row.status ? 0 : 1; // 切换状态，确保为 number 类型
  ElMessage.success($t('common.operateSuccess'));
}
</script>
